package ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LENOVO
 * Date: 2024-08-02
 * Time: 20:19
 */
public class DeleteOperation implements Ioperation {
    @Override
    public void work(BookList bookList) {
        int currentPos = bookList.getUsedSize();
        System.out.println("您要删除的书籍名称：");
        Scanner scanner = new Scanner(System.in);
        String bookName = scanner.nextLine();
        for (int i = 0; i < bookList.usedSize - 1; i++) {
            if (bookName.equals(bookList.books[i].getName())) {
                bookList.books[i] = bookList.books[i + 1];
            }
        }
        System.out.println("《"+bookName+"》" + "删除成功");
        bookList.setUsedSize(currentPos - 1);
    }
}
